-- add_counterattack_absorb
-- created by cheny3 Dec/17/2016
-- 概率增加反击吸血

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 对敌伤害触发
    trigger = function(who, prop, damage)
        if type(damage) == "number" then
            -- 不是本回合的标记
            if who.dbase:queryTemp("add_counterattack_absorb") ~= CombatM.getRound() then
                return;
            end

            -- 回复量，不能超过上限
            local curHp = who:queryAttrib("hp");
            local maxHp = who:queryAttrib("max_hp");
            local hp = damage * prop[3] / 1000;
            hp = math.min(hp, maxHp - curHp);
            if hp <= 0 then
                return;
            end

            if who.type == OBJECT_TYPE_USER then
                BonusM.doBonus({ 2, "hp", hp, }, "add_counterattack_absorb");
            else
                who:addAttrib("hp", hp);
            end
        else
            -- 标记需要吸血
            who.dbase:setTemp("add_counterattack_absorb", CombatM.getRound());
        end
    end,

    record = function(target, prop, path)
        return false;
    end
};